import 'package:flutter/material.dart';

class SplashView extends StatelessWidget {
  final AnimationController animationController;

  const SplashView({Key? key, required this.animationController})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    final firstHalfAnimation = Tween<Offset>(
      begin: const Offset(1, 0),
      end: const Offset(0, 0),
    ).animate(
      CurvedAnimation(
        parent: animationController,
        curve: const Interval(0.0, 0.2, curve: Curves.fastOutSlowIn),
      ),
    );

    final secondHalfAnimation = Tween<Offset>(
      begin: const Offset(0, 0),
      end: const Offset(-1, 0),
    ).animate(
      CurvedAnimation(
        parent: animationController,
        curve: const Interval(0.2, 0.4, curve: Curves.fastOutSlowIn),
      ),
    );

    final textOpacityAnimation = Tween<double>(
      begin: 0.0,
      end: 1.0,
    ).animate(
      CurvedAnimation(
        parent: animationController,
        curve: const Interval(0.0, 0.2, curve: Curves.fastOutSlowIn),
      ),
    );

    final buttonOpacityAnimation = Tween<double>(
      begin: 0.0,
      end: 1.0,
    ).animate(
      CurvedAnimation(
        parent: animationController,
        curve: const Interval(0.1, 0.2, curve: Curves.fastOutSlowIn),
      ),
    );

    return SlideTransition(
      position: firstHalfAnimation,
      child: SlideTransition(
        position: secondHalfAnimation,
        child: SafeArea(
          child: Container(
            decoration: const BoxDecoration(
              gradient: LinearGradient(
                colors: [
                  Color(0xFFFA7CBB),
                  Color(0xFFFFB6C1),
                  Color(0xFFFFC0CB),
                ],
                begin: Alignment.topLeft,
                end: Alignment.bottomRight,
              ),
            ),
            child: LayoutBuilder(
              builder: (context, constraints) {
                // 响应式设计参数
                final screenHeight = constraints.maxHeight;
                final screenWidth = constraints.maxWidth;
                final isSmallScreen = screenWidth < 400 || screenHeight < 700;
                
                // 动态计算尺寸
                final iconSize = isSmallScreen ? 80.0 : 120.0;
                final titleFontSize = isSmallScreen ? 28.0 : 36.0;
                final subtitleFontSize = isSmallScreen ? 16.0 : 20.0;
                final buttonWidth = screenWidth * 0.7;
                final buttonHeight = isSmallScreen ? 50.0 : 60.0;
                
                return Column(
                  children: [
                    // 顶部空间
                    SizedBox(height: screenHeight * 0.1),
                    
                    // 主要内容区域
                    Expanded(
                      child: Column(
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: [
                          // 爱心图标
                          AnimatedBuilder(
                            animation: animationController,
                            builder: (context, child) {
                              return Transform.scale(
                                scale: 0.8 + (0.2 * textOpacityAnimation.value),
                                child: Container(
                                  width: iconSize,
                                  height: iconSize,
                                  decoration: BoxDecoration(
                                    color: Colors.white.withOpacity(0.9),
                                    shape: BoxShape.circle,
                                    boxShadow: [
                                      BoxShadow(
                                        color: Colors.black.withOpacity(0.1),
                                        blurRadius: 20,
                                        offset: const Offset(0, 10),
                                      ),
                                    ],
                                  ),
                                  child: Icon(
                                    Icons.favorite,
                                    color: const Color(0xFFFA7CBB),
                                    size: iconSize * 0.5,
                                  ),
                                ),
                              );
                            },
                          ),
                          
                          SizedBox(height: screenHeight * 0.05),
                          
                          // 标题
                          AnimatedBuilder(
                            animation: textOpacityAnimation,
                            builder: (context, child) {
                              return Opacity(
                                opacity: textOpacityAnimation.value,
                                child: Padding(
                                  padding: EdgeInsets.symmetric(
                                    horizontal: screenWidth * 0.1,
                                  ),
                                  child: Column(
                                    children: [
                                      Text(
                                        '我们的小宇宙',
                                        style: TextStyle(
                                          fontSize: titleFontSize,
                                          fontWeight: FontWeight.bold,
                                          color: Colors.white,
                                          shadows: [
                                            Shadow(
                                              color: Colors.black.withOpacity(0.3),
                                              offset: const Offset(0, 2),
                                              blurRadius: 4,
                                            ),
                                          ],
                                        ),
                                        textAlign: TextAlign.center,
                                      ),
                                      
                                      SizedBox(height: screenHeight * 0.02),
                                      
                                      Text(
                                        '记录属于我们的美好时光',
                                        style: TextStyle(
                                          fontSize: subtitleFontSize,
                                          color: Colors.white.withOpacity(0.9),
                                          fontWeight: FontWeight.w300,
                                        ),
                                        textAlign: TextAlign.center,
                                      ),
                                    ],
                                  ),
                                ),
                              );
                            },
                          ),
                        ],
                      ),
                    ),
                    
                    // 底部按钮区域
                    AnimatedBuilder(
                      animation: buttonOpacityAnimation,
                      builder: (context, child) {
                        return Opacity(
                          opacity: buttonOpacityAnimation.value,
                          child: Padding(
                            padding: EdgeInsets.only(
                              bottom: screenHeight * 0.1,
                              left: screenWidth * 0.1,
                              right: screenWidth * 0.1,
                            ),
                            child: GestureDetector(
                              onTap: () {
                                print("🚀 启动页面按钮被点击！");
                                // 直接跳转到主应用，而不是继续动画
                                Navigator.of(context).pushReplacementNamed('/main');
                              },
                              child: Container(
                                width: buttonWidth,
                                height: buttonHeight,
                                decoration: BoxDecoration(
                                  gradient: const LinearGradient(
                                    colors: [
                                      Colors.white,
                                      Color(0xFFF8F8FF),
                                    ],
                                    begin: Alignment.topLeft,
                                    end: Alignment.bottomRight,
                                  ),
                                  borderRadius: BorderRadius.circular(buttonHeight / 2),
                                  boxShadow: [
                                    BoxShadow(
                                      color: Colors.black.withOpacity(0.2),
                                      blurRadius: 15,
                                      offset: const Offset(0, 5),
                                    ),
                                  ],
                                ),
                                child: Center(
                                  child: Text(
                                    '开始我们的旅程',
                                    style: TextStyle(
                                      fontSize: isSmallScreen ? 18.0 : 20.0,
                                      fontWeight: FontWeight.bold,
                                      color: const Color(0xFFFA7CBB),
                                    ),
                                  ),
                                ),
                              ),
                            ),
                          ),
                        );
                      },
                    ),
                  ],
                );
              },
            ),
          ),
        ),
      ),
    );
  }
}